package com.greathf.hf_ywgl.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

@Slf4j
@Component
@Configuration
public class  RestTemplateConfig {

    @Autowired
    public RequestConfig requestConfig;

    @Bean
    public RestTemplate restTemplate(@Qualifier("ClientHttpRequestFactory")ClientHttpRequestFactory factory){
        log.info("RestTemplate初始化完成");
        return new RestTemplate(factory);
    }

    @Bean
    public ClientHttpRequestFactory ClientHttpRequestFactory(){
        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
        factory.setConnectTimeout(requestConfig.connectTimeout);
        factory.setReadTimeout(requestConfig.readTimeout);
        return factory;
    }
}

